package com.jz.partclass.mapper;

import com.jz.legalpersonclass.model.LegalPersonVo;
import com.jz.legalplantclass.entity.LegalVO;
import com.jz.partclass.model.PartSelectVo;
import com.jz.partclass.model.PartUpdateVo;
import com.jz.partclass.model.PartVo;
import com.jz.planclass.model.PlanClassVo;
import com.jz.subclass.model.SubClassVo;
import com.jz.util.ResultVo;
import org.apache.ibatis.annotations.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * Created by WISE on 2021/12/26.
 */
@Mapper
public interface PartMapper {


    List<PartVo> queryData(PartSelectVo partSelectVo);

    int queryCount(PartSelectVo partSelectVo);

    @Select("select * from partclass where code = #{code}")
    PartVo queryByCode(String code);

    @Select("select * from partclass where name = #{name}")
    PartVo queryByName(String name);

    @Insert("insert into partclass(name,code,subCode,planCode,status,createTime,createName)" +
            "values(#{name},#{code},#{subCode},#{planCode},#{status},#{createTime},#{createName})")
    void add(PartVo classVo);

    @Select("select * from partclass where id = #{id}")
    List<PartVo> queryById(Integer id);

    @Select("select code subCode from subclass where subName = #{subName}")
    PartVo queryBySubName(@NotBlank(message = "备件小类名称不能为空") String subName);

    @Select("select code planCode from planclass where planName = #{planName}")
    PartVo queryByPlanName(@NotBlank(message = "备件小类名称不能为空") String planName);

    @Select("select *  from legalpersonclass where legalPersonName = #{legalPersonName}")
    LegalPersonVo queryByLegalName(@NotBlank(message = "法人名称不能为空") String legalPersonName);

    @Select("select legalPersonCode legalCode,legalPersonName legalName from legalpersonclass where userId = #{userId}")
    List<PartVo> queryByUserId(Integer userId);

    @Select("select * from subclass ")
    List<SubClassVo> queryAll();

    @Select("select * from planclass ")
    List<PlanClassVo> queryAll2();

    //@Insert("insert into partlegal(partCode,legalCode) values (#{code},#{legalCode})")
    void add1(PartVo classVo);

    @Update("update partclass set name = #{name},status = #{status},updateTime = #{updateTime},updateName = #{updateName},subCode = #{subCode},planCode = #{planCode} where id = #{id}")
    int update(PartVo classVo);

    //
    @Update("update partclass set status = #{status},updateTime = #{updateTime},updateName = #{updateName} where id = #{id}")
    void updateStatus(PartVo classVo);

    @Delete("delete from partlegal where partCode = #{code}")
    void delete(String code);

    void insertPartLegal(@Valid PartUpdateVo partUpdateVo);


//    @Insert("insert into legalplantclass(legalPlantCode,legalPersonCode,legalPlantDec,enabled,createTime,createName) values(#{legalPlantCode},#{legalPersonCode},#{legalPlantDec},#{enabled},#{createTime},#{createName})")
//    void add1(LegalVO legalVO);
}
